package com.bbcare.department.plat.service.impl;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bbcare.department.plat.service.IBsSmsTemplateService;
import com.bbcare.followup.plat.store.ibatis.ISmsTemplateDAO;

@Service
public class BsSmsTemplateService implements IBsSmsTemplateService {
	
	Logger logger = Logger.getLogger(BsSmsTemplateService.class); 
	
	@Autowired
	private ISmsTemplateDAO smsTemplateDAO;
	/**
	 * 根据type、type+code 类型 查询某一类型下的参数值列表 
	 * 先查科室下类型  如果为空 则查系统配置的类型
	 * @return
	 * @throws Exception 
	 */
	public String getSmsTemplateByCondition(Map<String,Object> param) throws Exception{
		/*Map<String,Object> paramTemp = new HashMap<String,Object>();
		paramTemp.put("deptId",param.get("deptId"));
		paramTemp.put("type",param.get("type"));*/
		param.put("status","1");
		StringBuilder smsContent=  new StringBuilder();
		Map<String,Object> smsTemplateMap = smsTemplateDAO.selectSmsTemplateByCondition(param);
		
		if(null == smsTemplateMap){
			//param.put("deptId",Constants.SYSTEM_CODE_TYPE);
			param.remove("tenantId");
			param.remove("deptId");
			param.put("tenantId","0");
			smsTemplateMap = smsTemplateDAO.selectSmsTemplateByCondition(param);
		}
		
		if(null != smsTemplateMap && null != smsTemplateMap.get("smsTemplate") ){
			if(StringUtils.isBlank(smsTemplateMap.get("sign").toString())){ //没定义签名 用默认 或者不签名
				smsContent.append("");
			}else{
				smsContent.append(smsTemplateMap.get("sign").toString());
			}
			
			smsContent.append(smsTemplateMap.get("smsTemplate"));
		}
		return smsContent.toString();
	}
	
}
